package com.appcenter.application.controller;


import com.appcenter.application.input.externalapi.DataSynchronizeInput;
import com.appcenter.application.service.HrToApplicationService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("services/data/api")
@Api(value = "HR向管理中心数据同步", description = "HR向管理中心数据同步")
public class HrToApplicationController {

    @Autowired
    HrToApplicationService hrToApplicationService;
    @ApiOperation(value = "数据同步", notes = "数据同步", produces = "application/json")
    @PostMapping("/datasynchronize")
    public ResponseEntity<JsonResult> DataSynchronize(@RequestBody DataSynchronizeInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setSuccess(true);
            r.setResult(hrToApplicationService.DataSynchronize(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "清除历史数据", notes = "清除历史数据", produces = "application/json")
    @PostMapping("/cleardata")
    public ResponseEntity<JsonResult> ClearData(@RequestBody DataSynchronizeInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setSuccess(true);
            r.setResult(hrToApplicationService.ClearData());
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }



}
